﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using COM.Domain;
using System.Web.Mvc.Html;

namespace System.Web.Helpers
{
    public static class SampleAppDeptDropDownListExtensions
    {
        public static MvcHtmlString DeptDropDownList<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes)
        {
            var deptService = COM.Web.Unity.Instance.GetService<SampleApp.Service.ISysDeptService>();
            var deptList = deptService.GetSysDeptList();
            var selectItemList = deptList.Select(i => new SelectListItem() { Selected = false, Value = i.DeptCode, Text = i.DeptName }).ToList();
            selectItemList.Insert(0, new SelectListItem() { Selected = false, Value = string.Empty, Text = "-" });
            return SelectExtensions.DropDownListFor(helper, expression, selectItemList, htmlAttributes);
        }
    }
}